<extend name="Public/Dialog/Common"/>
<block name="pageContent">
    <div class="bjui-pageContent">
        <form action="<if condition="!TPH_CUSTOM_FORM"><literal>__ACTION__</literal><else />{:U('Builder/createCustomForm')}</if>" class="pageForm" data-toggle="validate" method="post">
            <!-- 菜单id号 -->
            <input type="hidden" name="model_id" value="{:I('id')}"/>
            <input type="hidden" name="id" value="<literal>{$vo.id|default=I('id')}</literal>"/>
                <if condition="count(parse_config_attr($model['field_group'])) gt 1">
                <ul class="nav nav-tabs" role="tablist">
                    <volist name=":parse_config_attr($model['field_group'])" id="group">
                        <li <eq name="key" value="1">class="active"</eq>>
                        <a href="#{$model.name}tab{$key}" role="tab" data-toggle="tab">{$group}</a>
                        </li>
                    </volist>
                </ul>
                </if>
                <div <if condition="count(parse_config_attr($model['field_group'])) gt 1">
                    class="tab-content"
                </if>>
                    <volist name=":parse_config_attr($model['field_group'])" id="group">
                    <div id="{$model.name}tab{$key}" class="tab-pane fade <eq name="key" value="1">active in</eq>">
                        <fieldset>
                        <volist name="fields[$key]" id="field">
                            <div class="col-md-6">
                            <if condition="$field['is_show'] == 1 || $field['is_show'] == 3">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        {$field['title']}
                                        <notempty name="field['remark']">
                                            <span class="check-tips">（{$field['remark']})</span>
                                        </notempty>
                                    </div>
                                    <div class="panel-body">
                                        <switch name="field.type">
                                            <case value="num">
                                                <input type="text" class="text input-mid" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]}</literal>">
                                            </case>
                                            <case value="string">
                                                <input type="text" class="text input-large" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]}</literal>">
                                            </case>
                                            <case value="textarea">
                                                <label class="textarea input-large">
                                                    <textarea name="{$field.name}"><literal>{$vo[</literal>{$field['name']}<literal>]}</literal></textarea>
                                                </label>
                                            </case>
                                            <case value="date">
                                                <input type="text" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]|date='Y-m-d',###}</literal>" data-toggle="datepicker" data-rule="date" placeholder="请选择日期" />
                                            </case>
                                            <case value="datetime">
                                                <input type="text" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]|date='Y-m-d H:i:s',###}</literal>" data-toggle="datepicker" placeholder="请选择时间" />
                                            </case>
                                            <case value="bool">
                                                <select name="{$field.name}">
                                                <if condition="!TPH_CUSTOM_FORM">
                                                <literal><volist name=":parse_field_attr(</literal>"{$field['extra']}"<literal>)" id="vo"></literal>
                                                <option value="{$key}" <if condition="!TPH_CUSTOM_FORM"><literal><eq name="vo[</literal>{$field['name']}<literal>]" value="$key">selected</eq></literal></if>
                                                        >{$vo}
                                                        </option>
                                                <literal></volist></literal>
                                                </if>
                                                </select>
                                            </case>
                                            <case value="select">
                                                <select name="{$field.name}">
                                                <if condition="!TPH_CUSTOM_FORM">
                                                <literal><volist name=":parse_field_attr(</literal>"{$field['extra']}"<literal>)" id="vo"></literal>
                                                <option value="{$key}" <if condition="!TPH_CUSTOM_FORM"><literal><eq name="vo[</literal>{$field['name']}<literal>]" value="$key">selected</eq></literal></if>
                                                        >{$vo}
                                                        </option>
                                                <literal></volist></literal>
                                                </if>
                                                </select>
                                            </case>
                                            <case value="radio">
                                            <if condition="!TPH_CUSTOM_FORM">
                                            <literal><volist name=":parse_field_attr(</literal>"{$field['extra']}"<literal>)" id="vo"></literal>
                                                    <input type="radio" value="{$key}" name="{$field.name}" <if condition="!TPH_CUSTOM_FORM"><literal><eq name="vo[</literal>{$field['name']}<literal>]" value="$key">checked="checked"</eq></literal></if>>{$vo}
                                            <literal></volist></literal>
                                            </if>
                                            </case>
                                            <case value="checkbox">
                                            <if condition="!TPH_CUSTOM_FORM">
                                            <literal><volist name=":parse_field_attr(</literal>"{$field['extra']}"<literal>)" id="vo"></literal>
                                                <input type="checkbox" value="{$key}" name="{$field.name}[]" <if condition="!TPH_CUSTOM_FORM"><literal><if condition="check_document_position({$vo[</literal>{$field['name']}<literal>],$key)">checked="checked"</if></literal></if>>{$vo}
                                            <literal></volist></literal>
                                            </if>
                                            </case>
                                            <case value="editor">
                                                <label class="textarea">
                                                    <textarea name="{$field.name}" data-toggle="kindeditor" data-minheight="200"><literal>{$vo[</literal>{$field['name']}<literal>]}</literal></textarea>
                                                </label>
                                            </case>
                                            <case value="file">
                                                <div class="controls">
                                                    <input type="file" id="upload_file_{$field.name}">
                                                    <input type="hidden" name="{$field.name}" value="{:think_encrypt(json_encode(get_table_field($vo[$field['name']],'id','','File')))}"/>
                                                    <div class="upload-img-box">
                                                        <literal><present name="vo[</literal>{$field['name']}<literal>]">
                                                            <div class="upload-pre-file</literal>"><span class="upload_icon_all"></span>{$vo[$field['name']]|get_table_field=###,'id','name','File'}</div>
                                                        </present>
                                                    </div>
                                                </div>
                                                <script type="text/javascript">
                                                    //上传文件
                                                    $.CurrentNavtab.find("#upload_file_{$field.name}").uploadify({
                                                        "height"          : 30,
                                                        "swf"             : "__BJUI/plugins/uploadify/scripts/uploadify.swf",
                                                        "fileObjName"     : "download",
                                                        "buttonText"      : "上传附件",
                                                        "uploader"        : "{:U('File/upload',array('session_id'=>session_id()))}",
                                                        "width"           : 120,
                                                        'removeTimeout'	  : 1,
                                                        "onUploadSuccess" : function(file, data){
                                                            var data = $.parseJSON(data);
                                                            if(data.status){
                                                                var name = "{$field.name}";
                                                                $.CurrentNavtab.find("input[name="+name+"]").val(data.data);
                                                                $.CurrentNavtab.find("input[name="+name+"]").parent().find('.upload-img-box').html(
                                                                        "<div class=\"upload-pre-file\">" +
                                                                        "<span class=\"upload_icon_all\"></span>" + data.info +
                                                                        "</div>"
                                                                );
                                                            } else {
                                                                $(this).alertmsg('error', data.info);
                                                            }
                                                        },
                                                        'onFallback' : function() {
                                                            alert('未检测到兼容版本的Flash.');
                                                        }
                                                    });
                                                </script>
                                            </case>
                                            <case value="picture">
                                                <div class="controls">
                                                    <input type="file" id="upload_picture_{$field.name}">
                                                    <input type="hidden" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]}</literal>" id="cover_id_{$field.name}"/>
                                                    <div class="upload-img-box">
                                                        <literal><notempty name="vo[</literal>{$field['name']}<literal>]">
                                                            <div class="upload-pre-item</literal>">
                                                                <img src="{$vo[$field['name']]|get_cover='path'}" style="max-width:500px;max-height:200px;"/>
                                                                <span onclick="delthispic{$field.name}(this)" dataid="{$v}," class="fa fa-trash" style="font-size:20px;"></span>
                                                            </div>
                                                        </notempty>
                                                    </div>
                                                </div>
                                                <script type="text/javascript">
                                                    //上传单图
                                                    $.CurrentNavtab.find("#upload_picture_{$field.name}").uploadify({
                                                        "height"          : 30,
                                                        "swf"             : "__BJUI/plugins/uploadify/scripts/uploadify.swf",
                                                        "fileObjName"     : "download",
                                                        "buttonText"      : "上传图片",
                                                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                        "width"           : 120,
                                                        'removeTimeout'	  : 1,
                                                        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                                                        "onUploadSuccess" : function(file, data){
                                                                var data = $.parseJSON(data);
                                                                var src = '';
                                                                if(data.status){
                                                                    $.CurrentNavtab.find("#cover_id_{$field.name}").val(data.id);
                                                                    src = data.url || '__ROOT' + data.path
                                                                    $.CurrentNavtab.find("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                                                                            '<div class="upload-pre-item">' +
                                                                            '<img src="' + src + '" style="max-width:500px;max-height:200px;"/>' +
                                                                            '<span onclick="delthispic{$field.name}(this)" dataid="{$v}," class="fa fa-trash" style="font-size:20px;"></span>'+
                                                                            '</div>'
                                                                    );
                                                                } else {
                                                                    $(this).alertmsg('error', data.info);
                                                                }
                                                            },
                                                            'onFallback' : function() {
                                                                alert('未检测到兼容版本的Flash.');
                                                            }
                                                        });
                                                    /**
                                                     * 删除单图, 更新数据
                                                     */
                                                     function delthispic{$field.name}(obj) {
                                                        var dataids = '';   // 图片标识数据
                                                        $(obj).parent().remove();               // 移除父结点
                                                        // 更新数据
                                                        $.CurrentNavtab.find('#cover_id_{$field.name}').val('');
                                                    }
                                                </script>
                                            </case>
                                            <case value="uploadpics">
                                                <!-- 批量上传 -->
                                                <input type="file" id="upload_all_{$field.name}">
                                                <input type="hidden" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]}</literal>" id="input_upload_all{$field.name}"/>
                                                <div id="uploadpics_piclist{$field.name}">
                                                    <ul class="highslide-gallery">
                                                        <literal><notempty name="vo[</literal>{$field['name']}<literal>]"></literal>
                                                        <php>
                                                         $pics=explode(',', $vo[$field['name']]);
                                                         foreach($pics as $v){
                                                         if($v!=''){
                                                        </php>
                                                            <li>
                                                                <a href="__ROOT{$v|get_cover='path'}" target="_blank">
                                                                    <img src="__ROOT{$v|get_cover='path'}" style="max-width:500px;max-height:200px;"/></a>
                                                                    <span onclick="delthispics{$field.name}(this)" dataid="{$v}," class="fa fa-trash" style="font-size:20px;"></span>
                                                            </li>
                                                        <php>
                                                            }
                                                        }
                                                        </php>
                                                        <literal></notempty></literal>
                                                    </ul>
                                                </div>
                                                <script type="text/javascript">
                                                    //上传多图
                                                    $.CurrentNavtab.find("#upload_all_{$field.name}").uploadify({
                                                        "height" : 30,
                                                        "swf" : "__BJUI/plugins/uploadify/scripts/uploadify.swf",
                                                        "fileObjName" : "download",
                                                        "buttonText" : "批量上传图片",
                                                        "uploader" : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                        "width" : 120,
                                                        'removeTimeout' : 1,
                                                        'fileTypeExts' : '*.jpg; *.png; *.gif;',
                                                        "onUploadSuccess" : function(file, data){
                                                                var data = $.parseJSON(data);
                                                                var src = '';
                                                                if(data.status){
                                                                    src = data.url || '__ROOT' + data.path;
                                                                    var value = '<li>' +
                                                                            '<a href="'+src+'" class="highslide" onClick="return hs.expand(this)">' +
                                                                            '<img src="' + src + '" style="max-width:1000px;max-height:200px;"/></a>' +
                                                                            '<span onclick="delthispics{$field.name}(this)" dataid="'+data.id+'," class="fa fa-trash" style="font-size:20px;"></span>' +
                                                                            '</li>';

                                                                    // 图片数据
                                                                    $.CurrentNavtab.find('#uploadpics_piclist{$field.name} ul').append(value);

                                                                    // 更新图片id数据
                                                                    var dataids = "";
                                                                    console.log($.CurrentNavtab.find('#uploadpics_piclist{$field.name} .fa-trash').length);
                                                                    $.CurrentNavtab.find('#uploadpics_piclist{$field.name} .fa-trash').each(function(){
                                                                        dataids += $(this).attr('dataid');
                                                                    })
                                                                    console.log(dataids);
                                                                    $.CurrentNavtab.find('#input_upload_all{$field.name}').val(dataids);
                                                                } else {
                                                                    $(this).alertmsg('error', data.info);
                                                                }
                                                            },
                                                            'onFallback' : function() {
                                                                alert('未检测到兼容版本的Flash.');
                                                            }
                                                        });
                                                    /**
                                                     * 删除多图, 更新数据
                                                     */
                                                     function delthispics{$field.name}(obj) {
                                                        var dataids = '';   // 图片标识数据
                                                        $(obj).parent().remove();               // 移除父结点
                                                        // 更新数据
                                                        $.CurrentNavtab.find('#uploadpics_piclist{$field.name} .fa-trash').each(function(){
                                                            dataids += $(this).attr('dataid');
                                                        })
                                                        $.CurrentNavtab.find('#input_upload_all{$field.name}').val(dataids);
                                                    }
                                                </script>
                                            </case>
                                            <case value="editor">
                                                <label class="textarea">
                                                    <div style="display: inline-block; vertical-align: middle;">
                                                        <textarea name="{$field.name}" class="j-content" style="width: 700px;" data-toggle="kindeditor" data-minheight="200"><literal>{$vo[</literal>{$field['name']}<literal>]}</literal></textarea>
                                                    </div>
                                                </label>
                                            </case>
                                            <default/>
                                            <input type="text" class="text input-large" name="{$field.name}" value="<literal>{$vo[</literal>{$field['name']}<literal>]}</literal>"></switch>
                                    </div>
                                </div>
                            </if>
                                </div>
                        </volist>
                        </fieldset>
                    </div>
                    </volist>
                </div>
        </form>
    </div>
</block>